#!/usr/bin/sh
APP_DEPLOY_DIR=$1

echo "Update service script"

SCRIPT_LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rm -rf /tmp/sdCloud_service_management
mkdir /tmp/sdCloud_service_management
cp $SCRIPT_LOCATION/*-service.sh /tmp/sdCloud_service_management/
chmod +x /tmp/sdCloud_service_management/*.sh

SED_RESULT_VALUE=$(echo $APP_DEPLOY_DIR | sed 's/\//\\\//g')
cat $APP_DEPLOY_DIR/_Deployment/sdcloud-modelrun-agent.token.sh | sed "s/__(SdCloud.ModelRunAgent.DeployDir)__/$SED_RESULT_VALUE/" > $APP_DEPLOY_DIR/_Deployment/sdcloud-modelrun-agent.sh

sudo /tmp/sdCloud_service_management/install-service.sh $APP_DEPLOY_DIR
